package project.demo1.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
@WebServlet("/login.do")
public class login extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userName = req.getParameter("userName");
        String userPSW = req.getParameter("userPSW");
        if (userName.equals("aa") && userPSW.equals("123")) {
            HttpSession session = req.getSession();
            session.setAttribute("userName", userName);
            session.setAttribute("userPSW", userPSW);
            resp.sendRedirect("stu.do");
        }else{
            resp.sendRedirect("login.html");
        }
    }
}
